<template>
    <div class="c-share">
        <div class="share-wrapper">
            <div class="share-close">
                <i class="icon" @click="_close"></i>
            </div>
            <div class="share-title">
                <div class="line"></div>
                <div class="title">分享给好友</div>
                <div class="line"></div>
            </div>
            <!-- <p class="text">小伙伴已经获得商品收益￥{{price}}，大家一起赚钱吧!</p> -->
            <div class="share-img">
                <div class="img wx" @click="e_share(0)">
                    <span>微信好友</span>
                </div>
                <div class="img py" @click="e_share(1)">
                    <span>朋友圈</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { tokenPost, jtpost, gtpost, tokenLink, jtgetk } from '@api/axiosByToken'
import { Utils } from '@t/utils'
import WebShare from '@imgs/share/webshare.png'
export default {
	name: 'share',
	data() {
		return {
			isApp: '',
		}
	},
	props: {
		price: {
			type: String,
		},
	},
	methods: {
		_close() {
			this.$emit('closeShare')
		},
		// 获取微信分享需要的timestamp、noncestr和signature
		getWeChatInfo() {},
		// 好友分享
		e_share(n) {
			Boolean(n) ? this.shareToPark() : this.shareToFriend()
		},

		// 分享给好友
		shareToFriend() {
			if (typeof Wechat == 'undefined') {
				this.shareAtWeChat(2)
			} else {
				this.appShareToFriend()
			}
		},

		// 分享朋友圈
		shareToPark() {
			if (typeof Wechat == 'undefined') {
				this.shareAtWeChat(1)
			} else {
				this.appShareToPark()
			}
		},
		// 唤起手机网页微信分享
		shareAtWeChat(n) {
			var mshare = new mShare({
				title: 'Polo商城，邀您下载',
				url: 'https://www.pgyer.com/sDdN',
				desc: 'Polo商城，邀您下载',
				img:
					'https://com-jiaozheng-oss.oss-cn-qingdao.aliyuncs.com/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20181010135706.png',
			})
			mshare.init(n)
		},
		// ==========================================APP内分享微信好友👇=======================================================//
		appShareToFriend() {
			let _this = this
			Wechat.share(
				{
					message: {
						title: 'Polo商城',
						description: '阅汇诚品，一个会赚钱的APP',
						// thumb: './image/1530326955.png',
						mediaTagName: 'TEST-TAG-001',
						messageExt: '这是第三方带的测试字段',
						messageAction: '',
						media: {
							type: Wechat.Type.IMAGE,
							image:
								'https://com-jiaozheng-oss.oss-cn-qingdao.aliyuncs.com/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20181010135706.png',
						},
					},
					scene: Wechat.Scene.SESSION, // share to SESSION
				},
				function() {
					// alert("Success");
					_this.e_closeshare()
				},
				function(reason) {
					// alert("Failed: " + reason);
				},
			)
		},
		// ==========================================APP内分享微信好友👆=======================================================//
		// ==========================================APP内分享微信朋友圈👇=====================================================//
		appShareToPark() {
			let _this = this
			Wechat.share(
				{
					message: {
						title: 'Polo商城',
						description: '阅汇诚品，一个会赚钱的APP',
						// thumb: './image/1530326955.png',
						mediaTagName: 'TEST-TAG-001',
						messageExt: '这是第三方带的测试字段',
						messageAction: '',
						media: {
							type: Wechat.Type.IMAGE,
							image:
								'https://com-jiaozheng-oss.oss-cn-qingdao.aliyuncs.com/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20181010135706.png',
						},
					},
					scene: Wechat.Scene.Timeline, // share to Timeline
				},
				function() {
					// alert("Success");
					_this.e_closeshare()
				},
				function(reason) {
					// alert("Failed: " + reason);
				},
			)
		},
		// ==========================================APP内分享微信朋友圈👆=====================================================//
	},
	mounted() {
		// 判断当前环境是App还是浏览器
		// this.isApp = Utils.isapp()
	},
}
</script>
